﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
 
using BOHVote.BLL;
using BOHVote.Entity;

namespace BOH.MasterPage
{
    public partial class MasterPage : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["User"] != null)
            {
                BHUser user = (BHUser)Session["User"];
                this.labUserName.InnerText = user.UserName;
                if (user.UnitID.Trim().Length > 0)
                {
                    labUnit.Text = "("+UnitClass.getUnitName(user.UnitID)+")";
                }
                if (user.GovernID.Trim().Length > 0)
                {
                    labUnit.Text = "(" + UnitClass.GetGovernName(user.GovernID) + ")";
                }
                Setvisible(user.RightType);
                if(Session["ApplyPeriod"]==null)
                    Session["ApplyPeriod"] = PeriodClass.getAperiod().Tables[0].Rows[0]["ApplyPeriodID"].ToString();
            }
            else
            {
                Session["user"] = null;
                Session.Abandon();
                Session.Clear();
                Response.Redirect("../login.aspx");
            }
        }

        protected void Setvisible(string UserType)
        {
            switch (UserType)
            {
                case "C":
                case "A":
                    divAccreditation.Visible = true;
                    divManagement.Visible = true;
                    divInformation.Visible = true;
                    divTest.Visible = true;
                    divInterview.Visible = true;
                    divInterview.Visible = true;
                    divReoprts.Visible = true;
                    //divSystem.Visible = true;
                    break;
                case "G":
                    divAccreditation.Visible = true;
                    divManagement.Visible = false;
                    divInformation.Visible = true;
                    divTest.Visible = false;
                    divInterview.Visible = false;
                    divReoprts.Visible = false;
                    break;
                case "U":
                case "P":
                    divAccreditation.Visible = false;
                    divManagement.Visible = false;
                    divInformation.Visible = true;
                    divTest.Visible = false;
                    divInterview.Visible = false;
                    divReoprts.Visible = false;
                    break;
                case "Q":
                    divAccreditation.Visible = false;
                    divManagement.Visible = false;
                    divInformation.Visible = false;
                    divTest.Visible = false;
                    divInterview.Visible = true;
                    divInterview.Attributes.Remove("class");
                    divInterview.Attributes.Add("class", "menuShow");
                    divReoprts.Visible = false;
                    divManagement.Visible = false;
                    break;
                case "S":
                    divAccreditation.Visible = false;
                    divManagement.Visible = false;
                    divInformation.Visible = false;
                    divTest.Visible = false;
                    divInterview.Attributes.Remove("class");
                    divInterview.Attributes.Add("class", "menuShow");
                    divInterview.Visible = false;
                    divInterview.Visible = true;
                    divReoprts.Visible = false;
                    break;
                default:
                    break;
            }
        }

        protected void lnkQuit_Click(object sender, EventArgs e)
        {
            Session["user"] = null;
            Session.Abandon();
            Session.Clear();
            Response.Redirect("../login.aspx");
        }
    }
}
